//
//  KYRecentSearchText.m
//  Haizijiaoyuquan
//
//  Created by Kai Yu on 1/18/14.
//  Copyright (c) 2014 Zhang Kai Yu. All rights reserved.
//

#import "KYRecentSearchText.h"
@interface KYRecentSearchText ()
@property (nonatomic) UILabel *label;

@end
@implementation KYRecentSearchText

- (id)initWithFrame:(CGRect)frame
{
    return [self initWithText:nil color:nil];
}

- (id)initWithText:(NSString *)text color:(UIColor *)color
{
    self = [super initWithFrame:CGRectZero];
    if (self) {
        _label = [[UILabel alloc] init];
        _label.textAlignment = NSTextAlignmentCenter;
      //  _label.font = [UIFont fontWithName:FZLTXH size:14];
        _label.text = text;
        _label.textColor = color;
        _label.lineBreakMode = NSLineBreakByTruncatingMiddle;
        [self addSubview:_label];
    }
    return self;
}

- (void)layoutSubviews
{
    _label.frame = self.bounds;
}

- (void)sizeToFit
{
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.label.intrinsicContentSize.width, self.label.intrinsicContentSize.height);
}

- (CGSize)intrinsicContentSize
{
    return self.label.intrinsicContentSize;
}

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    self.highlighted = YES;
    [self sendActionsForControlEvents:UIControlEventTouchDown];
    return YES;
}

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    if (self.isTouchInside) {
        self.highlighted = YES;
        [self sendActionsForControlEvents:UIControlEventTouchDragInside];
    } else {
        self.highlighted = NO;
        [self sendActionsForControlEvents:UIControlEventTouchDragOutside];
    }
    return YES;
}

- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    self.highlighted = NO;
    
    if (self.isTouchInside) {
        [self sendActionsForControlEvents:UIControlEventTouchUpInside];
    } else {
        [self sendActionsForControlEvents:UIControlEventTouchUpOutside];
    }
}

- (void)cancelTrackingWithEvent:(UIEvent *)event
{
    self.highlighted = NO;
    [self sendActionsForControlEvents:UIControlEventTouchCancel];
}

- (void)setHighlighted:(BOOL)highlighted
{
    if (highlighted) {
        [UIView animateWithDuration:0.2 animations:^{
            
            self.alpha = 0.2;
        }];
    } else {
        [UIView animateWithDuration:0.2 animations:^{
            
            self.alpha = 1;
        }];
    }
}

- (void)didMoveToSuperview
{
    if (self.superview) {
        
    }
}


@end
